package neuralNetworks;

import java.io.Serializable;
import java.util.ArrayList;

public class Neuron implements Serializable {

	private static final long serialVersionUID = -9118022433345195239L;

	protected transient double net = 0.;

	public transient double act = 0.;

	public double bias;

	public Functions actFunc;

	public ArrayList<Connection<? extends Neuron>> sendConns = new ArrayList<Connection<? extends Neuron>>();

	public ArrayList<Connection<? extends Neuron>> empfConns = new ArrayList<Connection<? extends Neuron>>();

	public Neuron() {
	}

	public Neuron(Functions f, double b) {
		actFunc = f;
		this.bias = b;
	}

	private void computeNet() {
		net = bias;
		for (int c = 0; c < empfConns.size(); c++) {
			Neuron sender = empfConns.get(c).sender;
			net += sender.act * empfConns.get(c).weight;
		}
	}

	public void computeActivity() {
		computeNet();
		act = actFunc.calc(net);
	}

	public void setAct(double act) {
		this.act = act;
	}

	public double getAct() {
		return act;
	}

}
